import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
    login_info:'',
    cookie:'', // { "avatar":"http://wx.qlogo.cn/mmopen/z08iaicKAK4VziawqukT6vZJrPUBHEy4NJkuBqFXarKZIibO5p5pJNuEdV4JvHaSggNJqJDHqvQjOSsBIG8qcKs86f2eDlUCZjxw/0", "city":"æ·±å³", "cookie_id":"a9d54939fcc7d4a88c82e7a0fb4cbec4", "country":"ä¸­å½", "nickname":"å¼ æ¯æ´", "province":"å¹¿ä¸", "sex":"1", "user_id":"0", "wx_mp_id":"oEuzgwBwikW5L76rGMlAWm2DsOPM" }
    marker:{
        user:{obj:null,img:require('../assets/img/marker_passenger.png')},
        getOn:{obj:null,img:require('../assets/img/marker_getOn1.png')},
        start:{obj:null,img:require('../assets/img/marker_start.png')},
        end:{obj:null,img:require('../assets/img/marker_end.png')},
        fastCar:{img:require('../assets/img/marker_car.png')}
    },
    selectedCity:'中山',
    addrList:[], //搜索到的地址列表
    myPos:{   //添加的数据
        // lat:'',
        // lng:'',
        // province:'',
        // city:'',
        // addr:'',
        // name:''
    },
    startPos:{addr:'我的位置'}, //格式同myPos
    endPos:{addr:'你要去哪'}, //格式同myPos
    curTravel:'selectAddr', //selectAddr
    /*订单状态：
    0已取消 1待接单 2已接单 3已接客 4已到达起点 5待支付 6已支付 
    7乘客已评价 8司机取消订单 9线上支付 10司机已评价 11已到达终点 12预约等待
    */
    curOrder:{
        "id": "766",
        "status": "1",
        "departure": "广东省中山市齐乐路8号良安大厦",
        "dep_longitude": "113.41406",
        "dep_latitude": "22.51765",
        "destination": "广东省中山市药城路财富大厦7楼",
        "des_longitude": "113.39507",
        "des_latitude": "22.51253",
        "mileage_num": "0.00",
        "timer_num": "0.00",
        "order_amount": "0.00",
        "nickname": null,
        "sex": null,
        "realname": null,
        "avatar": null,
        "tel": null,
        "username": null,
        "cur_longitude": null,
        "cur_latitude": null,
        "count_finish": null,
        "level_star": "3",
        "is_friend": "0",
        "friend_name": null,
        "friend_tel": null,
        "is_book": "0",
        "book_time": null,
        "extra_fee": "0.00",
        "number": null,
        "car_model": null,
        "order_type": "1",
        "distance": 12399.756388189,
        "guest": null,
        "guest_tel": null,
        "max_coupon": []
    },
    travelStatusListen:false,
    curDriverPos:'',  //当前司机的位置
    curDriverMaker:null,
    driverNearbyList:[], //附近的司机位置
    driverNearbyMakerList:[],

    myInfo:'',
    // {
        // "avatar": null,
        // "nickname": "请设置昵称",
        // "realname": null,
        // "sex": "0",
        // "industry": null,
        // "position": null,
        // "tel": "13554767324",
        // "amount": "0.00",
        // "is_verify": "0"
    // },
    myCoupon:[
        {
            "id": "264",
            "coupon_code": "C9600F801C5B1FCEC9FCD48045ECCD0D",
            "type": "1",//优惠券类型，1是现金券，2是折扣券
            "user_id": "67",
            "amount": "100.00",//满减的金额
            "failure_time": "1504800000",
            "title": "现金券",
            "remark": "满10元可抵扣100元车费",
            "channel": "后台发放",
            "species": "通用券",
            "effective_time": "1500393600",
            "min_limit_amount": "10.00"//车费超过此数才能用此券
        },//type=1计算支付价格公式：车费-满减金额
        {
            "id": "263",
            "coupon_code": "6E7FC3AF52310378CBEB74963701D7F4",
            "type": "2",
            "user_id": "67",
            "amount": "0.50",//满减的幅度
            "failure_time": "1608912000",
            "title": "折扣券",
            "remark": "满10元可打0.5折",
            "channel": "后台发放",
            "species": "通用券",
            "effective_time": "1500393600",
            "min_limit_amount": "10.00"
        }//type=2计算支付价格公式：车费*满减幅度
    ], //我的代金券
    commonAddr:''
}

const getters = {
    login_info(state){
        return state.login_info
    },
    cookie(state){
        return state.cookie
    },
    marker(state){
        return state.marker
    },
    selectedCity(state){
        return state.selectedCity
    },
    addrList(state){
        return state.addrList
    },
    myPos(state){
        return state.myPos
    },
    startPos(state){
        return state.startPos
    },
    endPos(state){
        return state.endPos
    },
    curTravel(state){
        return state.curTravel
    },
    curOrder(state){
        return state.curOrder
    },
    travelStatusListen(state){
        return state.travelStatusListen
    },
    curDriverPos(state){
        return state.curDriverPos
    },
    curDriverMaker(state){
        return state.curDriverMaker
    },
    driverNearbyList(state){
        return state.driverNearbyList
    },
    driverNearbyMakerList(state){
        return state.driverNearbyMakerList
    },
    myInfo(state){
        return state.myInfo
    },
    myCoupon(state){
        return state.myCoupon
    },
    commonAddr(state){
        return state.commonAddr
    },
}

const mutations = {
    _cookie(state,cookie){
        state.cookie = cookie
    },
    _login_info(state,info){
        state.login_info = info
    },
    _switchCity(state,city){
        state.selectedCity = city
    },
    _loadAddrList(state,addrList){
        state.addrList = addrList
    },
    _location(state,{type,pos}){
        if(!type){
            console.log(`必须指定type`)
            return
        }
        state[type]=pos
    },
    _switchTravel(state,travel){
        state.curTravel=travel
    },
    _curOrder(state,order){
        state.curOrder=order
    },
    _travelStatusListen(state,isStrap){
        state.travelStatusListen=isStrap
    },
    _curDriverPos(state,pos){
        state.curDriverPos=pos
    },
    _curDriverMaker(state,marker){
        state.curDriverMaker=marker
    },
    _driverNearbyList(state,posList){
        state.driverNearbyList=posList
    },
    _driverNearbyMakerList(state,markerList){
        state.driverNearbyMakerList=markerList
    },
    _myInfo(state,myInfo){
        state.myInfo=myInfo
    },
    _myCoupon(state,couponArr){
        state.myCoupon=couponArr
    },
    _commonAddr(state,addrs){
        state.commonAddr=addrs
    }
}

const actions = {
    cookie({commit},cookie){
        commit('_cookie',cookie)
    },
    login_info({commit},info){
        commit('_login_info',info)
    },
    switchCity({commit},city){
        commit('_switchCity',city)
    },
    loadAddrList({commit},addrList){
        commit('_loadAddrList',addrList)
    },
    location({commit},{type,pos}){
        commit('_location',{type,pos})
    },
    switchTravel({commit},travel){
        commit('_switchTravel',travel)
    },

    curOrder({commit},order){
        commit('_curOrder',order)
    },
    travelStatusListen({commit},isStrap){
        commit('_travelStatusListen',isStrap)
    },
    //司机位置
    curDriverPos({commit},pos){
        commit('_curDriverPos',pos)
    },
    curDriverMaker({commit},marker){
        commit('_curDriverMaker',marker)
    },
    //附近司机位置及动态路径
    driverNearbyList({commit},posList){
        commit('_driverNearbyList',posList)
    },
    driverNearbyMakerList({commit},markerList){
        commit('_driverNearbyMakerList',markerList)
    },
    myInfo({commit},myInfo){
        commit('_myInfo',myInfo)
    },
    myCoupon({commit},couponArr){
        commit('_myCoupon',couponArr)
    },
    commonAddr({commit},addrs){
        commit('_commonAddr',addrs)
    }
}



export default new Vuex.Store({
    state,
    getters,
    mutations,
    actions,
    // modules:{

    // }
})